import { useMutation, useQueryClient } from "react-query";
import useServer from "server";
import { TaskType } from "types";

export const useEditTask = () => {
  const client = useServer();
  const queryClient = useQueryClient();

  return useMutation(
    (params: Partial<TaskType>) => {
      return client(`tasks/${params.id}`, { data: params, method: "PATCH" });
    },
    {
      onSuccess: () => queryClient.invalidateQueries("tasks"),
      onMutate: async (target) => {
        console.log(target);
      },
    }
  );
};
